/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/
// 改进方案1
// var a='hello',b='lagou',c='I ♥ U'
function promisifyStringWithDelay(value, delay = 10) {
  return new Promise((resolve, reject) => {
    try {
      setTimeout(() => resolve(value), delay)
      // throw new Error('mistake happen for test')
    } catch (error) {
      reject(error)
    }
  })
}


var a = 'hello'
promisifyStringWithDelay(a).then(value => {
  let b = 'lagou'
  return promisifyStringWithDelay(value + b)
})
  .then(value => {
    let c = 'I ♥ U'
    return promisifyStringWithDelay(value + c)
  })
  .then(console.log)
  .catch(error => {
    console.log(error.message)
  })

// 改进方案2 貌似不满足10ms的延迟设计
// Promise.all()